#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time	: 2024/3/29 14:18
# @Author  : jize.liu
# @File	: Assets_Replace.py
# @声明	 : 版权由 刘继泽 所有,如有疑问，需要帮助请联系刘继泽
import maya.cmds as cmds
import maya.mel as mel

class Check_Assets_Replace():
	def Check_Assets_Replace(self):
		Chrs = ["Z:/AnimationSeries/A10/Assets/Chr/C0090ZengSS/RIG/A10_C0090ZengSS_RIG.ma" , "Z:/AnimationSeries/A10/Assets/Chr/C0020LXQ/RIG/A10_C0020LXQ_RIG.ma" ,
				"Z:/AnimationSeries/A10/Assets/Chr/C0210SanYLH/RIG/A10_C0210SanYLH_RIG.ma" , "Z:/AnimationSeries/A10/Assets/Chr/C0100LinJY/RIG/A10_C0100LinJY_RIG.ma" ,
				"Z:/AnimationSeries/A10/Assets/Chr/C0500FaXiang/RIG/A10_C0500FaXiang_RIG.ma" , "Z:/AnimationSeries/A10/Assets/Chr/C0110XiaoYC/RIG/A10_C0110XiaoYC_RIG.ma" ,
				"Z:/AnimationSeries/A10/Assets/Chr/C0530YanHong/RIG/A10_C0530YanHong_RIG.ma" , "Z:/AnimationSeries/A10/Assets/Chr/C0510FaShan/RIG/A10_C0510FaShan_RIG.ma" ,
				"Z:/AnimationSeries/A10/Assets/Chr/C0010GuiLi/RIG/A10_C0010GuiLi_RIG.ma"]
		old_huangniao = "Z:/AnimationSeries/A10/Assets/Chr/C0220HuangN/RIG/A10_C0220HuangN_RIG.ma"
		new_huangniao = "Z:/AnimationSeries/A10/Assets/Chr/C0221HuangN/RIG/A10_C0221HuangN_RIG.ma"
		old_xuanshe = "Z:/AnimationSeries/A10/Assets/Chr/C0750HeiShuiXS/RIG/A10_C0750HeiShuiXS_RIG.ma"
		new_xuanshe = "Z:/AnimationSeries/A10/Assets/Chr/C0751HeiShuiXS/RIG/A10_C0751HeiShuiXS_RIG.ma"
		new_Env = "Z:/AnimationSeries/A10/Assets/Env/S1761HuaHaiZBPS/MODlow/A10_S1761HuaHaiZBPS_MODlow.ma"
		refFile_Node = []
		refNode = cmds.ls (type = "reference")
		refFiles = cmds.file (q = True , r = True)
		for refFile in refFiles :
			for Chr in Chrs :
				print (Chr)
				if Chr in cmds.file (q = True , r = True) :  # 检查字符文件是否在引用文件列表中
					Namespace = cmds.referenceQuery (Chr , namespace = True).split (":")[1]
					control_rig_node = Namespace + ":CONTROL_RIG_maya2020"
					if cmds.objExists (control_rig_node) :
						print (control_rig_node)
						# if cmds.attributeQuery ("ClothZhanSun" , node = control_rig_node , exists = True) :
						key = cmds.keyframe (control_rig_node , q = 1)
						if key :
							cmds.cutKey (control_rig_node , t = (key[0] , key[-1]))
						if cmds.attributeQuery ("ClothZhanSun" , node = control_rig_node , exists = True) :
							cloth_attr = control_rig_node + ".ClothZhanSun"

							cmds.setAttr (cloth_attr , 1)
							print ("------------------------------")
						if cmds.attributeQuery ("BodyZhanSun" , node = control_rig_node , exists = True) :
							cloth_attr = control_rig_node + ".BodyZhanSun"
							cmds.setAttr (cloth_attr , 1)
							print ("=================================")
					if "Z:/AnimationSeries/A10/Assets/Chr/C0010GuiLi/RIG/A10_C0010GuiLi_RIG.ma" == refFile :
						Namespace = cmds.referenceQuery (refFile , namespace = True).split (":")[1]
						control_rig_node = Namespace + ":CONTROL_RIG_maya2020"
						cloth_attr = control_rig_node + ".ClothZhanSunA"
						cmds.setAttr (cloth_attr , 0)
						cloth_attr = control_rig_node + ".ClothZhanSunB"
						cmds.setAttr (cloth_attr , 1)
						cloth_attr = control_rig_node + ".EyesZhanSun"
						cmds.setAttr (cloth_attr , 0)
						cloth_attr = control_rig_node + ".BodyZhanSun"
						cmds.setAttr (cloth_attr , 1)
						cloth_attr = control_rig_node + ".BodyZuiJiaoLXZhanSun"
						cmds.setAttr (cloth_attr , 0)
					if "Z:/AnimationSeries/A10/Assets/Chr/C0100LinJY/RIG/A10_C0100LinJY_RIG.ma" == refFile :
						Namespace = cmds.referenceQuery (refFile , namespace = True).split (":")[1]
						control_rig_node = Namespace + ":CONTROL_RIG_maya2020"
						cloth_attr = control_rig_node + ".ClothZhanSun"
						cmds.setAttr (cloth_attr , 0)
						cloth_attr = control_rig_node + ".ClothZhanSunB"
						cmds.setAttr (cloth_attr , 1)
						cloth_attr = control_rig_node + ".BodyZhanSun"
						cmds.setAttr (cloth_attr , 1)
						cloth_attr = control_rig_node + ".BodyZhanSunB"
						cmds.setAttr (cloth_attr , 0)
						print ("11111111111111111111")
				if old_xuanshe == refFile :
					node = cmds.referenceQuery (refFile , referenceNode = True)
					cmds.file (new_xuanshe , loadReference = node , type = "mayaAscii" , options = "v=0;")
					control_rig_node = Namespace + ":CONTROL_RIG_maya2020"
					if cmds.objExists (control_rig_node) :
						if cmds.attributeQuery ("BodyZhanSun" , node = control_rig_node , exists = True) :
							key = cmds.keyframe (control_rig_node , q = 1)
							if key :
								cmds.cutKey (control_rig_node , t = (key[0] , key[-1]))
							cloth_attr = control_rig_node + ".BodyZhanSun"
							cmds.setAttr (cloth_attr , 0)
							print ("22222222222222222222")
			if old_huangniao == refFile :
				print (old_huangniao)
				node = cmds.referenceQuery (old_huangniao , referenceNode = True)
				cmds.file (new_huangniao , loadReference = node , type = "mayaAscii" , options = "v=0;")
				print ("333333333333333")

		# 替换场景
		# if "Env" in refFile :
		#	cmds.file (refFile , removeReference = 1)

		# cmds.file (new_Env , r = 1 , type = "mayaAscii" , ignoreVersion = 1 , gl = 1 , mergeNamespacesOnClash = 0 , namespace = "A10_S1761HuaHaiZBPS_MODlow" , options = "v=0;")

		cmds.currentTime (116)
		cmds.currentTime (106)
		#cmds.file (save = True , f = 1)
		#print ("444444444444444")

